﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<title>评议选项</title>
@Html.Partial("LoadPanelPartial")
   @if (false)
   {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
   }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js",true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">
    var a = 0;
    $(document).ready(function () {
        var hdjson = $("#hdjson").val();
        if (hdjson != "") {
            var tableName = "additem";
            var json = JSON.parse(hdjson);
            var strTable = "";
            for (var i = 0; i < json.length; i++) {
                strTable += "<tr class='Add' id=\"" + i + "\"><td align='center' class='tdClass'><img src='" + rootPath + "/Content/images/delete.gif' width='9' height='9' style='cursor:pointer' onclick=delRow('" + tableName + "','" + i + "') /></td><td align='center' class='tdClass'><input type='text' style='width:60px' value=\"" + json[i]["FPeerReviewRuleScoreCd"] + "\" /></td><td align='center' class='tdClass'><input type='text' style='width:60px' value=\"" + json[i]["FScoreName"] + "\" /></td><td align='center' class='tdClass'><input type='text' style='width:50px' onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^\\d]/g,'')\" value=\"" + json[i]["FDispSeq"] + "\" /></td></tr>";
                a++;
            }
            $("#" + tableName).append(strTable);
        }


        var detailHtml = '{"FPeerReviewRuleScoreCd":"","FScoreName":"","FDispSeq":0}';

        $("#btnOK").bind("click", function () {
            var List = JSON.parse("[]");
            var ISNULL = true;
            $('.Add').each(function () {
                a++;
                var detailModel = JSON.parse(detailHtml);
                if ($.trim($(this).find('td').eq(1).find(':text').val()) != "") {
                    detailModel.FPeerReviewRuleScoreCd = $.trim($(this).find('td').eq(1).find(':text').val());
                } else {
                    alert("选项编号不能为空！");
                    ISNULL = false;
                    return false;
                }
                if ($.trim($(this).find('td').eq(2).find(':text').val()) != "") {
                    detailModel.FScoreName = $.trim($(this).find('td').eq(2).find(':text').val());
                } else {
                    alert("选项名字不能为空！");
                    ISNULL = false;
                    return false;
                }
                if ($.trim($(this).find('td').eq(3).find(':text').val()) != "") {
                    detailModel.FDispSeq = $.trim($(this).find('td').eq(3).find(':text').val());
                } else {
                    alert("选项顺序不能为空！");
                    ISNULL = false;
                    return false;
                }

                List.push(detailModel);
            });
            if (!ISNULL) {
                return;
            }
            var ListStr = "";
            if (List.length > 0) {
                Sort(List);
                ListStr = JSON.stringify(List);
            }
            window.returnValue = ListStr;
            window.close();
        });

        $("#btnCancel").bind("click", function () {
            window.close();
        });
    });
    function Sort(List) {
        var i = 0, len = List.length, j, d;
        for (; i < len; i++) {
            for (j = 0; j < len; j++) {
                if (List[i]["FDispSeq"] < List[j]["FDispSeq"]) {
                    d = List[j];
                    List[j] = List[i];
                    List[i] = d;
                }
            }
        }
        return List;       
     }
      
        function addRowEntry() {
            a++;
            var tableName = "additem";
            $("#" + tableName).append("<tr class='Add' id=\"" + a + "\"><td align='center' class='tdClass'><img src='" + rootPath + "/Content/images/delete.gif' width='9' height='9' style='cursor:pointer' onclick=delRow('" + tableName + "','" + a + "') /></td><td align='center' class='tdClass'><input type='text' style='width:60px' /></td><td align='center' class='tdClass'><input type='text' style='width:60px' /></td><td align='center' class='tdClass'><input type='text' style='width:50px' onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^\\d]/g,'')\" value='' /></td></tr>")
        }

        function delRow(tableId, rowId) {
            $("#" + tableId + " tr").remove("tr[id='" + rowId + "']");
        }
     </script>
</head>
<body>
    <div>
        <table width="100%" class="tableForm" border="0">
         <tr height="25"><td class="tdClass" align="center">@Html.DevExpress().Label(s => { s.Text = "评议选项"; }).GetHtml()</td></tr>
             <tr height="25">             
                <td colspan="4" class="tdClass">
                    <table width="100%" class="tableForm" id="additem">                     
                        <tr height="25">
                            <td width="6%" class="tdClass" height="30" style =" text-align:center">
                            <img src="@Url.Content("~/Content/images/add.gif")" style="cursor:pointer;font-size: 12px;"  onclick="addRowEntry()"/>
                            &nbsp;@Html.DevExpress().Label(settings => { settings.Text = "操作"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                            <td width="10%" class="tdClass" style =" text-align:center">@Html.DevExpress().Label(settings => { settings.Text = "编号"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                            <td width="10%" class="tdClass" style =" text-align:center">@Html.DevExpress().Label(settings => { settings.Text = "名称"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                            <td width="6%" class="tdClass" style =" text-align:center">@Html.DevExpress().Label(settings => { settings.Text = "显示顺序"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                        </tr>
                    </table>
                </td>
             </tr>  
        </table>    
    </div>
    <div style="padding: 0px; background: #efefef; width: 100%; font-size: 12px; text-align: center;">
        <table align="center">
            <tr>
                <td>
                    @Html.DevExpress().Button(settings =>
               {
                   settings.Name = "btnOK";
                   settings.Text = "确定";

                   settings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                   
               }).GetHtml()
                </td>
                <td>
                    @Html.DevExpress().Button(settings =>
               {
                   settings.Name = "btnCancel";
                   settings.Text = "取消";

                   settings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                   settings.CausesValidation = false;
                   
               }).GetHtml()
                </td>
            </tr>
        </table>
    </div>
    @Html.Hidden("hdjson", ViewData["json"])
</body>
</html>
